package org.jwos.plugin.file.domain;

import org.jwos.plugin.file.util.ObservedInputStream;

public class FileUploadInfo {
	
	private long totalCount;
	
	private ObservedInputStream input;
	
	public FileUploadInfo() {
	}
	
	public FileUploadInfo(ObservedInputStream input,long totalCount) {
		this.input = input;
		this.totalCount = totalCount;
	}
	
	public int getPercent() {
		return (int)(getUploadCount()*100/totalCount); 
	}	
	
	public long getSeconds() {
		if(input.getCompleteTime()>0) {
			return (input.getCompleteTime() - input.getStartTime()) / 1000;
		} else {
			return (System.currentTimeMillis() - input.getStartTime()) / 1000;
		}		
	}
	
	public long getSpeed() {
		return getUploadCount() / getSeconds();
	}
	
	public String getDescription() {
		return FolderType.formatSize(getUploadCount())+" / "+FolderType.formatSize(totalCount)
				+" ("+FolderType.formatSize(getSpeed())+"/s)";
	}

	public ObservedInputStream getInput() {
		return input;
	}

	public void setInput(ObservedInputStream input) {
		this.input = input;
	}

	public long getTotalCount() {
		return totalCount;
	}

	public void setTotalCount(long totalCount) {
		this.totalCount = totalCount;
	}

	public long getStartTime() {
		return input.getStartTime();
	}	

	public long getCompleteTime() {
		return input.getCompleteTime();
	}

	public long getUploadCount() {
		return input.getReadedCount();
	}

}
